export const getLabelsByKeys = (items: any[], keys: string[]): string[] => {
    const result: string[] = []

    function findItem(currentItems: any[], remainingKeys: string[]): boolean {
        if (remainingKeys.length === 0) return true

        const currentKey = remainingKeys[0]
        const foundItem = currentItems.find(item => item.key === currentKey)

        if (!foundItem) return false

        result.push(foundItem)

        if (remainingKeys.length > 1 && foundItem.children) {
            return findItem(foundItem.children, remainingKeys.slice(1))
        }

        return remainingKeys.length === 1
    }

    findItem(items, keys)
    return result
}
